import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;



public class ChatClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length != 2){
			System.err.println("FAIL INPUT. N00b");
			System.exit(1);
		}
		try {
			InetAddress address = InetAddress.getByName(args[0]);
			int port = Integer.parseInt(args[1]);
			
			Socket sock = new Socket(address, port);
			OutputStream os = sock.getOutputStream();
			ClientListener cl = new ClientListener(sock);
			cl.start();
			InputStreamReader converter = new InputStreamReader(System.in);
			BufferedReader in = new BufferedReader(converter);
			String command;
			while(true){
				command = in.readLine();
				command += '\n';
				os.write(command.getBytes());
				os.flush();
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
